package com.fei.spring.rabbitmq.two;

import com.fei.spring.rabbitmq.utils.RabbitMQUtils;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

//工作线程
public class Worker02 {
    //队列名称
    public static final String QUEUE_NAME = "hello02";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtils.getChannel();

        //接收消息
        DeliverCallback deliverCallback = (consumerTag,message) ->{
            System.out.println("接收到的消息"+new String(message.getBody()));
        };
        //消息接收被取消时，执行下面的内容
        CancelCallback cancelCallback =(consumerTag) -> {
            System.out.println(consumerTag+"：消息取消消费接口回调逻辑");
        };
        System.out.println("C2等待接收消息");
        //消息接收
        /*
         * 消费者消费消息
         * 1.消费哪个队列
         * 2.消费成功之后是否要自动应答 true自动应答 false手动应答
         * 3.消费者未成功消费的回调
         * 4.消费者取消消费的回调
         * */
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);
    }
}